/*
 * Copyright 2009 Douglas Lockamy, dlockamy_at_gmail.com
 * All rights reserved. Distributed under the terms of the MIT License.
 */
//Window Type
B_FLOATING_WINDOW = 1;

//Window flags
B_AVOID_FRONT = 100;

//Window Look Flags
B_NO_BORDER_WINDOW_LOOK = 200;

function BWindow(frame,title,type,flags)
{
    this.childList = new Array();

    this.trueWindowFrame = new BFrame(frame.x,frame.y,parseInt(frame.height) + 20,parseInt(frame.width)+5);

    //this.myWindow = benix.write("/local/window/"+title,CREATEDIR,frame,type,flags);

                    trueWindowFrame = new BFrame(10,10,500,600);
                    this.myWindow = new BDirectWindow(trueWindowFrame,title,"offset","length");

    this.myFrame = frame;
    this.myPublicFrame = new BFrame(parseInt(frame.x)-9,parseInt(frame.y)-10,parseInt(frame.height)-9,parseInt(frame.width)-2);
    this.myName = title;

    this.window_title = title; 

    this.titleBar = document.createElement('div');
    this.titleBar.id='titleBar_'+title;
    this.titleBar.style.borderBottom='solid';
    this.titleBar.style.borderWidth='1px';
    this.titleBar.style.borderColor='000000';    
    this.titleBar.style.backgroundColor='809090';
    this.titleBar.style.color='000000';
    this.titleBar.style.position="absolute";
    this.titleBar.style.top='5';
    this.titleBar.style.left='0';
    this.titleBar.style.width='100%';
    this.titleBar.innerHTML=title;
    this.titleBar.style.zIndex='1';
    this.titleBar.style.visibility="hidden";
    this.myWindow.addChildDiv(this.titleBar);
    
    this.winView = document.createElement('div');
    this.winView.id='wView_'+this.myName ;
    this.winView.style.position="absolute";   
    this.winView.style.top='25px';
    this.winView.style.left='0';
    this.winView.style.backgroundColor='cacaca';
    this.winView.style.width='99%';
    this.winView.style.height='99%';
    this.winView.style.overflow="hidden";
    this.winView.style.visibility="hidden";
    this.winView.style.zIndex='1';
    this.myWindow.addDiv(this.winView);


    this.deleteWin = function()
    {
        this.myWindow.deleteWin();
    };

    this.AddDiv = function(divName)
    {
        this.myWindow.AddDiv(divName);
    };
    
    this.addHTML = function(divName,innerHTML)
    {
        this.myWindow.AddHTML(divName,innerHTML);    
    };

    this.addChild = function(bView)
    {
        this.childList[this.childList.length]=bView;
        this.myWindow.addChild(bView);
        benix.write("/local/window/"+title+"/"+bView.getViewId(),CREATEDIR,frame,"sync",flags);
    };

    this.RemoveChild = function(child)
    {

    };

    this.Show = function()
    {
        var count=0;
        benix.write("/local/window/"+title+"/visibility",CREATEDATAFILE,"visible",null,null);
        
        this.titleBar.style.visibility="visible";
        this.winView.style.visibility="visible";
        this.myWindow.Show();
        while(count < this.childList.length)
        {
            this.childList[count].Show();
            count++;
        };
        
        return 0;
    };

    this.Hide = function()
    {

    };

    this.MessageReceived = function(message)
    {

    };

    this.WindowActivated = function()
    {

    };

    this.Zoom = function()
    {

    };

    this.Activate = function()
    {

    };

    this.IsActive = function()
    {

    };

    this.MoveBy = function(x,y)
    {

    };

    this.MoveTo = function(x,y)
    {

    };

    this.Quit = function()
    {

    };


    this.SetTitle = function(title)
    {

    };
    this.Bounds = function()
    {
        return this.myPublicFrame;
    };
   
};
